# _*_ coding:utf-8 _*_
# at:2023-11-24
# author:zizle
from fastapi import APIRouter
from db import FAConnection
from v1_all_api.constant import WORK_GROUPS
from v1_all_api.all_utils import datetime_utils
from v1_all_api.all_response import AllResponse


class CommonApi:
    def get_department_employee(self):
        sql = """
            SELECT u.admin_name,u.group_en,u.is_leader,
                   ru.id
            FROM work_user_extend As u
            INNER JOIN ruizy_user As ru ON u.user_id=ru.id
            WHERE u.end_date>=%s;
        """
        with FAConnection() as cursor:
            cursor.execute(sql, [datetime_utils.today()])
            u_list = cursor.fetchall()
        for u in u_list:
            u['gname'] = WORK_GROUPS.get(u['group_en'])
        return AllResponse.operate_successfully(data=u_list)


common_api = APIRouter()


@common_api.get('/groupEmployee/')
def get_department_group_employee():
    return CommonApi().get_department_employee()

